#include "DonorList.h"

#include "iostream"
#include "set"
#include "algorithm"
#include "string"
using namespace std;

DonorList::DonorList()
{
    (*this).donorList = new set<DonorType>;
}

void DonorList::addDonor(
    const string &newFirst,
    const string &newLast,
    int newMembershipNo,
    double donation)
{
    DonorType temporary(newFirst, newLast, 
                        newMembershipNo, donation);
    (*this).donorList->insert(temporary);
}

double DonorList::getNoOfDonors() const
{
    return (*this).donorList->size();
}

double DonorList::getTotalDonations() const
{
    double totalDonation = 0.0;
    for (auto iter = (*this).donorList->begin();
        iter != (*this).donorList->end(); iter++)
    {
        totalDonation += iter->getAmountDonated();
    }
    return totalDonation;
}

double DonorList::getHighestDonation() const
{
    double highestDonation = 0.0;
    for (auto iter = (*this).donorList->begin();
        iter != (*this).donorList->end(); iter++)
    {
        if (highestDonation < iter->getAmountDonated())
        {
            highestDonation = iter->getAmountDonated();
        }
    }
    return highestDonation;
}

bool DonorList::isEmpty() const
{
    return (*this).donorList->empty();
}

bool DonorList::searchID(int membershipNo) const
{   
    double membershipNoDouble = membershipNo;
    return find(
            (*this).donorList->begin(),
            (*this).donorList->end(),
            membershipNoDouble
    ) != (*this).donorList->end();
}

void DonorList::deleteDonor(int membershipNo)
{
    auto searchResult = find(
        (*this).donorList->begin(),
        (*this).donorList->end(),
        membershipNo
    );
    if (searchResult != (*this).donorList->end())
    {
        (*this).donorList->erase(*searchResult);
    }
}

void DonorList::printAllDonors() const
{
    for (auto iter = (*this).donorList->begin();
        iter != (*this).donorList->end();
        iter++)
    {
        iter->printMemberInfo();
    }
}

void DonorList::printAllDonations() const
{
    for (auto iter = (*this).donorList->begin();
        iter != (*this).donorList->end();
         iter++)
    {
        iter->printDonation();
    }
}

void DonorList::clearList()
{
    (*this).donorList->clear();
}

DonorList::~DonorList()
{
    delete (*this).donorList;
    (*this).donorList = nullptr;
}





